
import * as THREE from 'three';
export const getPostion = (group) => {
    // 地图mapGroup的包围盒计算
    const box3 = new THREE.Box3();//创建一个包围盒
    // .expandByObject()方法：计算层级模型group包围盒
    box3.expandByObject(group);

    //scaleV3表示包围盒长宽高尺寸
    const scaleV3 = new THREE.Vector3();
    // .getSize()计算包围盒长宽高尺寸
    box3.getSize(scaleV3)
    // 查看控制台包围盒大小，辅助设置相机参数
    console.log('查看包围盒尺寸', scaleV3);

    //scaleV3表示包围盒的几何体中心
    const center = new THREE.Vector3();
    // .getCenter()计算一个层级模型对应包围盒的几何体中心
    box3.getCenter(center);
    // 查看控制台包围盒集合中心，作为lookAt()参数
    console.log('查看几何中心', center);

    calcuPosition(group, center)

    return center

}

const calcuPosition = (group, center) => {
    group.position.x = group.position.x - center.x;
    group.position.y = group.position.y - center.y;
    group.position.z = group.position.z - center.z;
}